﻿<%@ WebHandler Language="C#" Class="uploadfile" %>

using System;
using System.Web;
using System.IO;
using System.Linq;

public class uploadfile : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string strResponse = "error";
        try
        {
            HttpPostedFile postedFile = context.Request.Files["Filedata"];
            string ID = context.Request["name"].ToString();
            string[] strArray = System.Text.RegularExpressions.Regex.Split(context.Request["folder"], "/");
            string strresult =context.Server.MapPath( @"~/User/avatar/") + ID + "_" + postedFile.FileName;
            postedFile.SaveAs(strresult);
            using (Up1VNDataContext dc = new Up1VNDataContext())
            {
                User U = dc.Users.Single(c => c.Users_Name == ID);
                U.Users_Avatar = ID + "_" + postedFile.FileName;
                dc.SubmitChanges();
            }
            context.Response.Write(strresult);
            context.Response.StatusCode = 200;
        }
        catch(Exception ex)
        {

        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}